<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //1.合并数组
        let arr1 = [1, 2, 3];
        let arr2 = [4, 5, 6];
        //我们想将两个数组 合并为 同一个
        //在es5中
        let arr0 = arr1.concat(arr2);
        //concat 会改变原数组 arr1
        console.log(arr0, arr1);
        //在es6中
        let arr = [...arr1, ...arr2];
        console.log(arr);

        let set = new Set([1, 2, 3]);
        //想将set数据 转换为数组
        let arr3 = [...set];
        console.log(arr3);

        //数组浅拷贝
        let arr5 = [1, 2, 3, ["张三", "李四"]]
        let arr4 = [...arr5];
        //这样实现的拷贝 是浅拷贝 简单类型的数组项互不影响 复杂类型的数组项 则还会互相影响
        arr4[0] = "王五";//互不影响
        console.log(arr4, arr5);

        arr4[3][0] = "赵四";//互相影响
        console.log(arr4, arr5);

        //实现对象的浅拷贝
        let obj = {
            name: "张三",
            age: 18,
            hobbies: ["吃", "喝"]
        }
        let obj1 = { ...obj };
        console.log(obj1, obj);
        obj.name = "李四";
        console.log(obj1, obj);
        obj.hobbies[0] = "玩";
        console.log(obj1, obj);
    </script>
</body>

</html>